package com.panfeng.xcloud.gateway.reptile;

import com.panfeng.xcloud.common.core.utils.SpringContextUtil;
import com.panfeng.xcloud.common.core.utils.StringUtils;
import com.panfeng.xcloud.gateway.config.AntiCrawlerPropConfig;
import lombok.extern.slf4j.Slf4j;

/**
 * IP反爬虫验证规则
 *
 * @author xiaobo
 * @version 1.0
 * @since 2019-05-21
 */
@Slf4j
public class IPAntiCrawlerRule extends AntiCrawlerRule {

    @Override
    public boolean antiCheck(String checkContent, String toBeCheckContent) {
        return true;
    }

    @Override
    public boolean antiCheck(String checkContent) {
        if (StringUtils.isEmpty(checkContent) ){
            log.info(">>> 当前，验证失败 <<<");
            return false;
        }
        AntiCrawlerPropConfig antiCrawlerPropConfig = SpringContextUtil.getApplicationContext().getBean(AntiCrawlerPropConfig.class);
        if(null == antiCrawlerPropConfig){
            log.info(">>> 无法从spring上下文获取到反爬虫配置信息,请检查服务端配置 <<<");
            return false;
        }

        return true;
    }
}
